<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" href="#(CONTEXT_PATH)/static/lib/layui/css/layui.css">
		<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
		<script src="#(CONTEXT_PATH)/static/lib/layui/layui.js" charset="utf-8"></script> 
	</head>
	<body>
		<br>
		<form id="editForm" class="layui-form" action="" onsubmit="submitForm()" style="width:90%">
		  <div class="layui-form-item">
		    <label class="layui-form-label">名称</label>
		    <div class="layui-input-block">
		      <input type="hidden" id="id" name="id" value="#(goods.id??)"  />
		      <input type="text" name="name"  value="#(goods.name??)"  lay-verify="name" autocomplete="off" placeholder="请输入标题" class="layui-input">
		    </div>
		  </div>
		  
		  <div class="layui-form-item">
		    <label class="layui-form-label">种类</label>
		    <div class="layui-input-block">
		    	<select id="category_id"  name="category_id">
		    		<option value="" >请选择</option>
		    		#for(gc : gcs)
		    		<option value="#(gc.id??)" >#(gc.name??)</option>
		    		#end
		    	</select>
		    
		    </div>
		  </div>
		  
		  <div class="layui-form-item">
		    <label class="layui-form-label">图片</label>
		    <div class="layui-input-block">
		      <input type="hidden" id="img" name="img" value="#(goods.img??)"  />
		      	<button type="button" class="layui-btn" id="test1">
					<i class="layui-icon">&#xe67c;</i>上传文件
				</button>
				
				#if(goods.img??)
				<button type="button" class="layui-btn" onclick="window.open('#(CONTEXT_PATH??)/upload/temp/#(goods.img??)')">
					查看
				</button>
				#end
		    </div>
		    </div>
		  </div>
		  
		  <div class="layui-form-item">
		    <label class="layui-form-label">库存</label>
		    <div class="layui-input-block">
		      <input type="text" name="store_count"  value="#(goods.store_count??)"  lay-verify="store_count" autocomplete="off" placeholder="请输入标题" class="layui-input">
		    </div>
		  </div>
		  
		  <div class="layui-form-item">
		    <label class="layui-form-label">过期时间</label>
		    <div class="layui-input-block">
		      <input type="text" id="pass_date" name="pass_date"  value="#(goods.pass_date??)"  lay-verify="pass_date"   class="layui-input">
		    </div>
		  </div>
		  
		  <div class="layui-form-item">
		    <label class="layui-form-label">单价</label>
		    <div class="layui-input-block">
		      <input type="text" name="price"  value="#(goods.price??)"  lay-verify="price" autocomplete="off" placeholder="请输入标题" class="layui-input">
		    </div>
		  </div>
		  
		  <div class="layui-form-item">
		    <label class="layui-form-label">成本</label>
		    <div class="layui-input-block">
		      <input type="text" name="cost"  value="#(goods.cost??)"  autocomplete="off" placeholder="请输入标题" class="layui-input">
		    </div>
		  </div>
		  
		  <div class="layui-form-item">
		    <label class="layui-form-label">内容</label>
		    <div class="layui-input-block">
		     <textarea name="description" placeholder="请输入内容" class="layui-textarea">#(goods.description??)
		     </textarea>
		    </div>
		  </div>
		  
		 
  		</form>
  		
   		<div class="layui-form-item">
		    <div class="layui-input-block">
		      <button class="layui-btn" onclick="submitData();">立即提交</button>
		    </div>
		  </div>
	</body>
	<script>
		var layer;
		var element;
		var laydate;
		$(function(){
			layui.use(['form','element','upload','laydate'],
			    function() {
		        layer = layui.layer;
		        element = layui.element;
		        laydate = layui.laydate;

				var upload = layui.upload;
		        
		        //执行实例
		        var uploadInst = upload.render({
		          elem: '#test1' //绑定元素
		          ,url: '#(CONTEXT_PATH??)/upload/' //上传接口
		          ,field:'file'
		          ,accept:'file'
		          ,done: function(res){
		            //上传完毕回调
		           $("#img").val(res.data.src);
		          }
		          ,error: function(){
		            //请求异常回调
		          }
		        });

		        laydate.render({
				    elem: '#pass_date' //指定元素
				});
		     });

			
			$("#category_id").val("#(goods.category_id??)");
		});
		
		function refresh(){
			console.log("aaa " + parent.currentTab);
			var obj = getCurrentTab();
			var src = obj.attr("src");
			alert(src);
		}
		
		function getCurrentTab(){
			var obj = parent.$("iframe[class='x-iframe']:eq("+parent.currentTab+")");
			return obj[0];
		}
		
		function submitData(){
			var formData = $("#editForm").serialize();
			//console.log(formData);
            //formData.append('b', 3);// 还可以添加额外的表单数据
            $.post('#(CONTEXT_PATH)/goods/save',formData,function(data) {
				//alert('完成');
				var obj = getCurrentTab();
				console.log(obj);
				obj.contentWindow.query();
           });
		}
		
		function submitForm(){
			submitData();
		}
		
	</script>
</html>
